package com.example.gybicycle.service;

import java.util.Date;
import com.example.gybicycle.common.entity.Result;
import com.example.gybicycle.common.enums.NumType;
import com.example.gybicycle.common.sql.CrudService;
import com.example.gybicycle.common.util.NumberUtil;
import com.example.gybicycle.entity.Member;
import com.example.gybicycle.entity.MemberPay;
import com.example.gybicycle.dao.MemberPayDao;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class MemberPayService extends CrudService<MemberPayDao, MemberPay> {
    @Override
    public MemberPay get(String id) {
        MemberPay table=super.get(id);
        return table;
    }
    public Result save(MemberPay entity,String loginId){
        int num=0;
        if(entity.getId()==null){
           
            num=dao.insert(entity);
        }else {
           
            num=dao.update(entity);
        }
        if(num>0)
            return Result.success(entity);
        else 
            return Result.fail("保存失败");
    }

    @Override
    public int insert(MemberPay entity) {
        entity.setId(NumberUtil.getNum(NumType.PAY));
        int num=super.insert(entity);
        return  num;
    }

    @Override
    public int insertByList(List<MemberPay> list) {
        for(MemberPay entity:list){
            entity.setId(NumberUtil.getNum(NumType.PAY));
        }
        return super.insertByList(list);
    }

    public List<MemberPay> findList(MemberPay entity){
        List<MemberPay> list=super.findList(entity);
//            @Schema(description = "付款类型 0 押金 1 骑行 2 退款 ")
//    private Integer payType;
        for(MemberPay pay:list){
            switch (pay.getPayType()){
                case 0:
                    pay.setTypeName("押金");
                case 1:
                    pay.setTypeName("骑行");
                case 2:
                    pay.setTypeName("退款");
            }
        }
        return list;
    }
public MemberPay getOne(MemberPay pay){
        return dao.getOne(pay);
}

}